package com.wizo.csb;

import java.util.Properties;

/**
 * Create a storage layer by dynamically classloading the specified storage class.
 * @author Wizo
 *
 */
public class StorageFactory {

	public static Storage newStorage(String storageName, Properties properties) 
			throws UnknownStorageException{
		ClassLoader classLoader = StorageFactory.class.getClassLoader();
		Storage storage;
		
		try{
			Class storageClass = classLoader.loadClass(storageName);
//			System.out.println("storageClass.getName() = "+storageClass.getName());
			storage = (Storage)storageClass.newInstance();
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
		
		storage.setProperties(properties);
		
		return new StorageWrapper(storage);
	}
}